package 管理员;

import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.CreateTopicsResult;
import org.apache.kafka.clients.admin.NewTopic;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.internals.Topic;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.*;

/**
 * x
 *
 *
 *
 */
public class Kafka01_Admin {
    public static void main(String[] args) {


        Properties props = new Properties();
        props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "114.251.235.19:9092"); // Kafka服务器地址
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());

        /**
         * 创建管理员对象
         */
        Admin admin = Admin.create(props);


        /**
         * 参数1；topic名称
         * 参数2：分区个数
         * 参数3：副本数了，short类型
         */
        short s=1;
        NewTopic newTopic = new NewTopic("topic_tesp",1,s);


        /**
         * admin创建主题
         */
        CreateTopicsResult topics = admin.createTopics(Arrays.asList(newTopic));


        admin.close();;
    }
}
